package com.avantis.common.utils;


import org.springframework.data.redis.connection.RedisZSetCommands;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Redis Commands Interface
 *
 * @author bolun@goldmantis.com
 * @version 1.0
 */
public interface IRedisCommands {
    void setIncrease(String key, int liveTime, byte[] value);
    /**
     * 添加key value 并且设置存活时间
     *
     * @param key key
     * @param value value
     * @param liveTime 过期时间 (秒)
     */
    void setExpire(String key, int liveTime, String value);

    /**
     * 添加hash value 并且设置存活时间
     *
     * @param key key
     * @param filed filed
     * @param value value
     * @param liveTime 过期时间 (秒)
     */
    //void setHashExpire(String key, String filed, String value, int liveTime);

    /**
     * 保存对象byte[]
     *
     * @param key key
     * @param filed filed
     * @param value value
     */
    void setHash(String key, String filed, byte[] value);

    Boolean setHashNX(String key, String field, byte[] value);

    /**
     * Set a timeout on the specified key.
     *
     * @param key key
     * @param liveTime liveTime
     */
    Boolean expire(String key, int liveTime);

    /**
     * 数据是否存在
     *
     * @param key key
     * @return true存在，false不存在
     */
    Boolean exists(String key);

    /**
     * 添加key value
     *
     * @param key key
     * @param value value
     *
     * @return Status code reply
     */
    void set(String key, String value);

    /**
     * 添加key value
     *
     * @param key key
     * @param value value
     *
     * @return Status code reply
     */
    void set(String key, String value, String charSet);

    /**
     * 添加 key value
     * @param key
     * @param value byte[]
     */
    void setBytes(String key, byte[] value);

    /**
     * 根据Key 获取value
     *
     * @param key key
     * @return value
     */
    byte[] get(String key);

    /**
     * 根据Key 获取byte value
     *
     * @param key key
     * @return byte value
     */
    //byte[] get(byte[] key);

    /**
     * 根据Key 获取Hash结构里元素的数量
     *
     * @param key key
     * @return Long value
     */
    //Long hashLength(String key);

    /**
     * 保存Hash结构数据
     *
     * @param key key
     * @param field field
     * @param value value
     * @return 操作结果
     */
    //Long hashSet(String key, String field, String value);

    /**
     * 保存Hash结构数据
     *
     * @param key key
     * @param field field
     * @param value value
     * @return 操作结果
     *
     */
    //Long hashSetByte(byte[] key, byte[] field, byte[] value);

    /**
     * 获取Hash结构数据对应filed的value
     *
     * @param key key
     * @param field field
     * @return value
     */
    byte[] hashGet(String key, String field);

    /**
     * 获取Hash结构数据对应filed的byte value
     *
     * @param key key
     * @param field field
     * @return byte value
     */
    //byte[] hashGetByte(String key, String field);

    /**
     * 数据是否存在Hash结构中
     *
     * @param key key
     * @param field field
     * @return true存在，false不存在
     */
    //Boolean hashExists(String key,String field);

    /**
     * 数据是否存在Hash结构中
     *
     * @param key key
     * @param field field
     * @return true存在，false不存在
     */
    //Boolean hashExists(byte[] key, byte[] field);

    /**
     * Increment the number stored at key by one. If the key does not exist or
     * contains a value of a wrong type, set the key to the value of "0" before
     * to perform the increment operation.
     * <p/>
     * INCR commands are limited to 64 bit signed integers.
     * <p/>
     * Note: this is actually a string operation, that is, in Redis there are
     * not "integer" types. Simply the string stored at the key is parsed as a
     * base 10 64 bit signed integer, incremented, and then converted back as a
     * string.
     *
     * @param key key
     * @return 增加后的值
     */
    //Long increase(String key);

    /**
     * 数据是否存在Hash结构中
     *
     * @param key1 key
     * @param key2 property
     * @return 删除是否成功
     */
    Long hashDel(final String key1, final String key2);

    Long del(final String key1);
    /**
     * 自增
     *
     * @param key key
     * @return
     */
    Long increase(final String key);

    Set<byte[]>  keys(final String pattern);

    Long lPush(final String key, final String value);

    List<byte[]> lRange(String key, long start, long end);

    Boolean zAdd(final String key, final String value, final double score);

    String[] zRange(final String key, final long start, final long end);

    String[] zRevRange(final String key, final long start, final long end);

    Double zScore(final String key, final String value);

    Long zCard(final String key);

    Long sCard(final String key);

    Long lLen(final String key);

    Set<RedisZSetCommands.Tuple> zRangeWithScores(final String key, final long start, final long end);

    Set<RedisZSetCommands.Tuple> zRevRangeWithScores(final String key, final long start, final long end);

    Map<byte[],byte[]> hashGetAll(final String key);

    List<byte[]> hMGet(final String key, final String... field);

    Set<byte[]> hKeys(final String key);

    Boolean setNx(final String key, final String value);

    Long sadd(String key, String value);

    Long srem(String key, String value);

    Boolean sismember(String key, String value);
}
